<%@ page pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="/inc/_html_head.jsp"></jsp:include>
</head>
<body>
<jsp:include page="/inc/_page_header.jsp"></jsp:include>

<div class="page-main">
	<!--左导航菜单-->
	<jsp:include page="/inc/_menu.jsp"></jsp:include>
	
	<!--主显示区域-->
	<div class="main">
	    <div class="wapper">
	        <h2>新增会员</h2>
	        <div class="view">
	            <form id="addForm" action="${pageContext.request.contextPath}/admin/add.do" method="post">
	                <div>
	                	<div>
	                		<label>管理员帐号：</label>
	                		<input name="username" type="text" class="G-text" placeholder="请输入管理员帐号"/>
	                		<span id="msg_username"></span>
	                	</div>
	                    <div>
		                    <label>管理员密码：</label>
		                    <input name="password" type="password" class="G-text" placeholder="请输入管理员密码"/>
		                    <span id="msg_password"></span>
	                    </div>
	                    <div>
	                    	<label>确认密码：</label>
	                    	<input id="repassword" type="password" class="G-text" placeholder="请输入确认密码密码"/>
	                    	<span id="msg_repassword"></span>
	                    </div>
	                    <div>
		                    <label>状态：</label>
		                    <select name="status">
		                    	<option value="1" selected="selected">激活</option>
		                    	<option value="0">禁用</option>
		                    </select>
	                    </div>
	                    <div><label>&nbsp;</label><button type="submit" >确定</button><button type="reset">重设</button></div>
	                </div>
	            </form>
	        </div>
	    </div>
	</div>
</div>

<!--左导航菜单-->
<jsp:include page="/inc/_page_footer.jsp"></jsp:include>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/placeholder.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/validator.js"></script>
<script type="text/javascript">
var flag_name = true;
var flag_password = true;
$(function(){
	$("#addForm").bind('submit',checkForm);

	$("input[name='username']").bind('blur',function(){
		var name = this.value;
		var msg = $("#msg_username");
		//用户名为空
		if($.trim(name) === ""){
			msg.text('请输入用户名');
			flag_name = false;
			return;
		}
		
		//用户名格式不正确
		if((name.length < 6) || (name.length > 16)){
			msg.text('用户名由6-16位字符组成.');
			flag_name = false;
			return;
		}
		$.ajax({
			type:'post',
			url:'${pageContext.request.contextPath}/admin/checkName.do',
			data:{name:""+name+""},
			success:function(data){
				if(data == "false"){
					flag_name = false;
					msg.text("帐号已存在！");
				}else{
					flag_name = true;
					msg.text("帐号可用！");
				}
			}
		});
	});
	
	
	$("input[name='password']").bind('blur',function(){
		var password = this.value;
		var msg = $("#msg_password");
		if(password === ""){
			 msg.text('请输入密码.');
			 flag_password = false;
			 return;
		 }
	 
		 if(password.length < 6){
			 msg.text('用户密码不能少6位，请注意区分大小写.');
			 flag_password = false;
			 return;
		 }
		 flag_password = true;
		 msg.text('');
	});
	
	$("#repassword").bind('blur',function(){
		var password = $("input[name='password']").val();
		var repassword = this.value;
		var msg = $("#msg_repassword");
		if(repassword === ""){
			 msg.text('请输入确认密码.');
			 flag_password = false;
			 return;
		 }
	 
		 if(password != repassword){
			 msg.text('两次输入的密码不符.');
			 flag_password = false;
			 return;
		 }
		 flag_password = true;
		 msg.text('');
	});
	
});	

function checkForm(){
	if(flag_name && flag_password) return true;
	return false;
}
</script>
</html>